﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DynamicChat.aspx.cs" Inherits="chatblog.usercate.DynamicChat" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
    <form action="chRoom.aspx" method="post" >
        <input  name="user_to_recid" value="" type="hidden"  id="user_to_recid"/>
        <input  type="submit" id="openChatRoomSubmit" value="确定"/>
    </form>
    <script type="text/javascript">
        window.onload = function() {
            init();
        }
        function init() {            
            var usertoRecid = getQueryString("torecid");
            if (usertoRecid != "") {
                var result = chatblog.usercate.DynamicChat.SetDynamicChatUserTos(usertoRecid);
                if (result.value != null) {//alert(result.value);
                    if (result.value == "") {
                        //closeWindow();
                        window.open("chRoom.aspx?torecid=" + usertoRecid, "newRoom", "height=500px, width=250px, top=0, left=800, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no", true );
                        setTimeout(function() {      
                            closeWindow();
                        }, 1000);
                    }
                    else if (result.value == "self") {
                        //alert("聊天室窗口在本地已经打开！");
                        closeWindow();
                    }
                    else if(result.value=="不能和自己聊天") {
                    alert(result.value);
                    closeWindow();
                    }
                    else {
                        //alert(result.value);
                        //closeWindow();
                        window.open("chRoom.aspx?torecid=" + usertoRecid, "newRoom", "height=500px, width=250px, top=0, left=800, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no", true);
                        setTimeout(function() {
                            closeWindow();
                        }, 1000);
                    }
                }
                else {
                    alert("参数异常！");
                    closeWindow();
                }
            }
        }
        
        function closeWindow() {
            window.opener = null;
            window.open("", "_self");
            window.close();
        }
        
        function getQueryString(queryName) {
            var queryValue = "";
            var queryFound = false;
            if (window.location.search != "") {
                var search = window.location.search;
                var i = 0;
                while (i <= search.length) {
                    start = i;
                    end = start + queryName.length;
                    if (search.substring(start, end) == queryName) {
                        queryFound = true;
                        break;
                    }
                    i++;
                }
                if (queryFound) {
                    start = end + 1;
                    end = search.indexOf("&", start);
                    if (end < start)
                        end = search.length;
                    var getvalue = search.substring(start, end);
                    return unescape(getvalue);
                }
            }
            return queryValue;
        }
    </script>
</body>
</html>
